<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('平台单位挂接非税单位')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i>平台单位
				</div>
				<div class="box-title">
				  	<label class="col-sm-7">是否挂接</label>
					<select name="gjzt" id="gjzt" class="col-sm-6">
					         <option value="">全部</option>
						     <option value="0">否</option>
							 <option value="1">是</option>
					</select>
				</div>
				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="hsdwtrees" class="ztree"></div>
			</div>
		</div>
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" id="dwbm" name="dwbm">
		                <input type="hidden" id="parentId" name="parentId">
						<div class="select-list">
							<ul>
								<li>
								    <a class="btn btn-success btn-rounded btn-sm" onclick="save()" shiro:hasPermission="system:user:save">
		                             <i class="fa fa-save"></i> 保存 </a>
								</li>
							</ul>
						</div>
					</form>
				</div> 
		        <div class="col-sm-12">
				    <div id="fsdwTrees" class="ztree"></div>
				</div>
			</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var saveFlag = [[${@permission.hasPermi('system:user:save')}]];
		var prefix = ctx + "system/ptgjfsdw";

		$(function() {
		    $('body').layout({ initClosed: false, west__size: 400 });
		    queryHsdwTree();
		    queryFsdwTree();
		});
		function queryHsdwTree()
		{
			var gjzt=$("#gjzt").val();
			var url = ctx + "system/ptgjfsdw/treeData/"+gjzt;
			var options = {
		        url: url,
		        id: "hsdwtrees",
		        expandLevel: 1,
		        onClick : zOnClick
		    };
			$.tree.init(options);
			
			function zOnClick(event, treeId, treeNode) {
				$("#dwbm").val(treeNode.id);
				$("#parentId").val(treeNode.pId);
			    queryFsdwTree(treeNode.id);
			}
		}
		function queryFsdwTree(dwbm){
			var url = ctx + "system/ptgjfsdw/fsdwtreeData?dwbm=" + dwbm;
			var options = {
				id: "fsdwTrees",
		        url: url,
		        check: { enable: true },
		        expandLevel: 0
		    };
			$.tree.init(options);
		}
		
		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});
		
		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});
		
		$('#btnRefresh').click(function() {
			queryHsdwTree();
		});
		
		
		function save() {
			var dwbm = $("input[name='dwbm']").val();
			var fsdwms = $.tree.getCheckedNodes();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/ptgjfsdw/save",
				data : {
					"dwbm": dwbm,
					"fsdwms": fsdwms
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					if (data.code==0){
						$.modal.alertWarning("保存成功");
					}else{
						$.modal.alertWarning(data.msg);	
					}
				}
			});
		}
		$("#gjzt").change(function(){
			queryHsdwTree();
		});
	</script>
</body>
</html>